package utilisateur;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import message.Message;

public class Utilisateur implements Serializable {

	protected String nom;
	protected String prenom;
	protected String login;
	protected String mdp;
	protected boolean enLigne;
	protected Map<String,List<Message>> messagesPrives;
	protected Map<String,List<tchat.Message>> messagesSalon;

	public Utilisateur(String nom, String prenom, String login, String mdp) throws RemoteException {
		super();
		this.nom = nom;
		this.prenom = prenom;
		this.login = login;
		this.mdp = mdp;
		this.enLigne = false;
		this.messagesPrives = new HashMap<String,List<Message>>();
		this.messagesSalon = new HashMap<String,List<tchat.Message>>();
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}
	
	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getMdp() {
		return mdp;
	}

	public void setMdp(String mdp) {
		this.mdp = mdp;
	}

	public boolean isEnLigne() {
		return enLigne;
	}

	public void setEnLigne(boolean enLigne) {
		this.enLigne = enLigne;
	}

	@Override
	public String toString() {
		return this.getClass().getSimpleName() + " [nom=" + nom + ", prenom=" + prenom + ", login="
				+ login + ", mdp=" + mdp + ", enLigne=" + enLigne +"]";
	}

	public Map<String, List<Message>> getMessagesPrives() {
		return messagesPrives;
	}

	public void setMessagesPrives(Map<String, List<Message>> messagesPrives) {
		this.messagesPrives = messagesPrives;
	}

	public Map<String, List<tchat.Message>> getMessagesSalon() {
		return messagesSalon;
	}

	public void setMessagesSalon(Map<String, List<tchat.Message>> messagesSalon) {
		this.messagesSalon = messagesSalon;
	}
	
	public void ajouteMessageSalon(String salon, tchat.Message message) {
		if(this.messagesSalon.containsKey(salon)) {
			this.messagesSalon.get(salon).add(message);
		}
		else {
			List<tchat.Message> l = new ArrayList<>();
			l.add(message);
			this.messagesSalon.put(salon, l);
		}
	}
}
